<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- CDN -->
    <!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css"> -->
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/fontawesome/css/all.min.css">
    <script src="../css/fontawesome/js/all.min.js"></script>
</head>

<body>
    <h2>用户管理</h2>
    <!-- 后端服务器 -->

    <i class="fa-solid fa-trash"></i>

    <button type="button" class="btn btn-info">Primary</button>


    <div class="btn btn-primary"> <i class="fa-solid fa-trash"></i> Primary</div>

    <table class="table table-striped">
        <thead>
            <tr class="table-dark">
                <th>用户名</th>
                <th>年龄</th>
                <th>性别</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>lili</td>
                <td>20</td>
                <td>girl</td>
            </tr>
            <tr>
                <td>lili</td>
                <td>20</td>
                <td>girl</td>
            </tr>
            <tr>
                <td>lili</td>
                <td>20</td>
                <td>girl</td>
            </tr>
        </tbody>
    </table>


    <script type="module">
        import PocketBase from '../js/pocketbase.es.js';
        // http://127.0.0.1:8090 数据库服务器地址
        const pb = new PocketBase('http://127.0.0.1:8090');

        // collection() 获取数据库的集合（表）
        // getList() promise 获取数据库的集合中分页数据
        /*
            100,
            "page": 1,
            "perPage": 30,
            "totalPages": 1,
            "totalItems": 2,
        */
        // getFullList() 获取数据库的集合中全部数据
        /*
            100
        */

        // getFirstListItem() 获取符合要求的所有记录中的第一条

        // getOne() 根据ID获取一条记录

        // create() 创建一条记录

        // update() 根据ID更新一条记录

        // delete() 根据ID删除一条记录

        // pb.collection('users').getList(2, 2)
        // pb.collection('users').getFullList()
        // pb.collection('users').getFirstListItem('')
        // pb.collection('users').getOne('1j8zdzmykkxkwpb')
        // pb.collection('users').create({
        //     "username": "xubaocai123",
        //     "email": "xubaocai123@example.com",
        //     "emailVisibility": true,
        //     "password": "12345678",
        //     "passwordConfirm": "12345678",
        //     "name": "薛宝钗",
        //     "phone": "18889876555",
        //     "gender": "2",
        //     "department": "3p5ckmni2yumo6z",
        //     "age": 123
        // })

        // pb.collection('users').update('1j8zdzmykkxkwpb', {
        //     name: '孙悟空123',
        //     age: '47500',
        // })

        // pb.collection('users').delete('byt6ygq5nbjhadj')
        //         .then((data) => {
        //             //获取成功
        //             console.log(data);
        //         }).catch((err) => {
        //             //获取失败
        //             console.dir(err);
        //         });
        (async () => {
            try {
                const data = await pb.collection('users').delete('byt6ygq5nbjhadj');
                console.log(data);
            } catch (error) {
                console.log(data);
            }
        })()





    </script>

</body>

</html>